package com.kevin.kitchenshow2.entity;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.w3c.dom.Node;

import com.kevin.kitchenshow2.KitchenShow;
import com.kevin.kitchenshow2.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;

public class SubCategory {
	private Node xmlNode;
	private Drawable image;
	private String name;
	private String id;
	private Boolean isLoad;
	private Boolean isLoadItem;
	private List<Item> lstItem;
	private Context context;

	public SubCategory() {

	}

	public SubCategory(Node node, Context context) {
		xmlNode = node;
		this.context = context;
		id = KitchenShow.getAttibuteOfNode(xmlNode, "id");
		Log.i("D", "Start load" + id);
		name = KitchenShow.getAttibuteOfNode(xmlNode, "name");
		String strUrl = KitchenShow.getAttibuteOfNode(xmlNode, "image");
		try {
			URL tUrl = new URL(strUrl);
			InputStream is = tUrl.openStream();
			image = Drawable.createFromStream(is, id);
			is.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Log.i("D", "Load image error " + id);
			e.printStackTrace();
			image = this.context.getResources().getDrawable(R.drawable.unkown);
		}
		Log.i("D", "finish load" + id);
	}

	public Boolean getIsLoadItem() {
		return isLoadItem;
	}

	public void setIsLoadItem(Boolean isLoadItem) {
		this.isLoadItem = isLoadItem;
	}

	public List<Item> getLstItem() {
		return lstItem;
	}

	public void setLstItem(List<Item> lstItem) {
		this.lstItem = lstItem;
	}

	public Node getXmlNode() {
		return xmlNode;
	}

	public void setXmlNode(Node xmlNode) {
		this.xmlNode = xmlNode;
	}

	public Drawable getImage() {
		return image;
	}

	public void setImage(Drawable image) {
		this.image = image;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Boolean getIsLoad() {
		return isLoad;
	}

	public void setIsLoad(Boolean isLoad) {
		this.isLoad = isLoad;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}
